package model;

import java.util.ArrayList;
import java.util.Scanner;

import service.Constan;
import service.ProjectAPI;
import service.implement.ProjectDAO;

public class Project {
	private int id;
	private String nameProject;
	private String startDate;
	private String endDate;
	public Project(){

	}
	public Project(int id, String nameProject, String startDate, String endDate) {
		super();
		this.id = id;
		this.nameProject = nameProject;
		this.startDate = startDate;
		this.endDate = endDate;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getNameProject() {
		return nameProject;
	}
	public void setNameProject(String nameProject) {
		this.nameProject = nameProject;
	}
	public String getStartDate() {
		return startDate;
	}
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}
	public String getEndDate() {
		return endDate;
	}
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	public Project inputProject() {
		ProjectAPI pj=new ProjectDAO();

		Scanner input=new Scanner(System.in);
		System.out.println("Enter your NameProject:");
		String nameProject=input.nextLine();
		if(pj.checkName(nameProject)){
			System.out.println("Nameproject da ton tai");
			return null;
		}
		while(nameProject.trim().equalsIgnoreCase("")){
			System.out.println("Name chua duoc nhap.Nhap lai!");
			nameProject=input.nextLine();
		}
		System.out.println("Enter StartDate:");
		String startDate=input.nextLine();
		while(startDate.trim().equalsIgnoreCase("")){
			System.out.println("startDate chua duoc nhap.Nhap lai!");
			startDate=input.nextLine();
		}
		if(!Constan.isValidDate(startDate)){
			System.out.println("Ngay nhap khong dung dinh dang.Nhap lai!(dd/mm/yyyy");
			startDate=input.nextLine();
		}
		System.out.println("Enter EndDate:");
		String endDate=input.nextLine();
		while(endDate.trim().equalsIgnoreCase("")){
			System.out.println("EndDate chua duoc nhap.Nhap lai!");
			endDate=input.nextLine();
		}
		if(!Constan.isValidDate(endDate)){
			System.out.println("Ngay nhap vao khong dung dinh dang.Nhap lai(dd/mm/yyyy");
			endDate=input.nextLine();
		}
		if(!Constan.checkDate(startDate, endDate)){
			System.out.println("Ngay ket thuc nho hon ngay bat dau");
			return null;
		}
		
		Project pj2=new Project(id,nameProject,startDate,endDate);
		return pj2;
	}
	public Project updateProject() {
		ProjectAPI pj=new ProjectDAO();
		Scanner ip=new Scanner(System.in);
		System.out.println("Enter  ID you want to update: ");
		int id=Integer.parseInt(ip.nextLine());
		if(pj.getProjectById(id)==null){
			System.out.println("Id khong ton tai");
			return null;
		}
		else{
			
			System.out.println("Thong tin ve id da co");
			System.out.println(Constan.DISPLAY_PJ);
			Project projt=pj.getProjectById(id);
			System.out.println(projt);		
		}
		System.out.println("Enter nameProject you want to update:");
		String nameProject=ip.nextLine();
		while(nameProject.trim().equalsIgnoreCase("")){
			System.out.println("NameProject chua duoc nhap.Vui long nhap lai! ");
			nameProject=ip.nextLine();
		}
		if(pj.checkName(nameProject)){
			System.out.println("Nameproject da ton tai.Nhap lai");
			nameProject=ip.nextLine();
		}
		System.out.println("Enter startDate you want to update:");
		String startDate=ip.nextLine();
		while(startDate.trim().equalsIgnoreCase("")){
			System.out.println("StartDate chua duoc nhap.Vui long nhap lai!");
			startDate=ip.nextLine();
		}
		if(!Constan.isValidDate(startDate)){
			System.out.println("Ngay nhap vao khong dung dinh dang.Nhap lai!");
			startDate=ip.nextLine();
		}
		System.out.println("Enter endDate you want to update:");
		String endDate=ip.nextLine();
		while(endDate.trim().equalsIgnoreCase("")){
			System.out.println("EndDate chua duoc nhap.Vui long nhap lai!");
			endDate=ip.nextLine();
		}
		if(!Constan.isValidDate(endDate)){
			System.out.println("EndDate nhap vao khong dung dinh dang.Nhap lai!");
			endDate=ip.nextLine();
		}
		Project pro=new Project(id,nameProject,startDate,endDate);
		return pro;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "|"+getId() + "\t\t|" + getNameProject()  + "\t\t\t|" + getStartDate()+"\t\t|"+getEndDate();
	}
	
}
